mylag = function(x,lag){

    if(lag>length(x)) warning("Lag is larger than input vector length, returning NA's") 

    if(lag<0)  return(c(rep(NA,abs(lag)),x[-(length(x):(length(x)+lag+1))]))
    if(lag==0) return(x)    
    if(lag>0)  return(c(x[-(1:lag)],rep(NA,lag)))

}
